﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Models;
using BLL;
using System.IO;

namespace Dryricenet.houTai
{
    public partial class shuffling_Add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //提交
        protected void Add_Button_Click(object sender, EventArgs e)
        {
            Rotationa r = new Rotationa();
            r.Title = txtTitle.Text.Trim();
            if (FileUpload1.HasFile)
            {
                if (CheckFileType(FileUpload1.FileName))
                {
                    string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + Path.GetExtension(FileUpload1.FileName);
                    string filePath = "~/houTai/lunboImg/" + fileName;
                    FileUpload1.SaveAs(MapPath(filePath));
                    r.image = filePath;
                }
            }
            if (FileUpload1.FileName != "") {
                if (RotationaBLL.lunboAddBLL(r))
                {
                    Response.Write("<script>alert('添加成功！')</script>");
                }
                else
                {
                    Response.Write("<script>alert('添加失败！')</script>");
                }
            } 
            else
                {
                    Response.Write("<script>javascript:alert('您还没有上传图片!');history.back();</script>");
                    Response.End();
                }
           
        }
       public bool CheckFileType(string filename)
        {
            string ext = Path.GetExtension(filename);
            switch (ext.ToLower())
            {
                case ".gif": return true;
                case ".png": return true;
                case ".jpg": return true;
                case ".jpeg": return true;
                default: return false;
            }
        }
    }
}